
// TextEditView.cpp : implementation of the CTextEditView class
//

#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "TextEdit.h"
#endif

#include "TextEditDoc.h"
#include "TextEditView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CTextEditView

IMPLEMENT_DYNCREATE(CTextEditView, CFormView)

BEGIN_MESSAGE_MAP(CTextEditView, CFormView)
	ON_WM_CONTEXTMENU()
	ON_WM_RBUTTONUP()
	ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
END_MESSAGE_MAP()

// CTextEditView construction/destruction

CTextEditView::CTextEditView()
	: CFormView(CTextEditView::IDD)
	, m_valEditor(_T(""))
{
	// TODO: add construction code here

}

void CTextEditView::OnEditPaste()
{
	m_ctrlEditor.SetSel(0, -1);
	m_ctrlEditor.Paste();
}

CTextEditView::~CTextEditView()
{
}

void CTextEditView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_RICHEDITEDITOR, m_ctrlEditor);
	DDX_Text(pDX, IDC_RICHEDITEDITOR, m_valEditor);
}

BOOL CTextEditView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CTextEditView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
}

void CTextEditView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
	ClientToScreen(&point);
	OnContextMenu(this, point);
}

void CTextEditView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
	theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}


// CTextEditView diagnostics

#ifdef _DEBUG
void CTextEditView::AssertValid() const
{
	CFormView::AssertValid();
}

void CTextEditView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CTextEditDoc* CTextEditView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTextEditDoc)));
	return (CTextEditDoc*)m_pDocument;
}
#endif //_DEBUG


// CTextEditView message handlers
